#!/usr/bin/env python
# -- coding=utf-8 --
from tornado import httpserver, ioloop, options
from tornado.web import *

options.define("port", 8000, type=int, help="请输入端口号")

class IndexHandler(RequestHandler):
    def get(self):
        self.write("hello")

class CityHandler(RequestHandler):
    def get(self, subject, city):
        self.write("<h1>subject:%s City:%s</h1>" % (subject, city))


class DateHandler(RequestHandler):
    def get(self, subject, date):
        self.write("<h1>subject:%sDate:%s</h1>" % (subject, date))


def main():
    options.options.parse_command_line()
    print(options.options.port)
    app = Application([
        (r'/$', IndexHandler),
        (r'/sub-city/(\w+)/(\w+)', CityHandler),
        (r'/sub-date/(?P<date>\d{4})/(?P<subject>\w+)', DateHandler),
    ])
    http_server = httpserver.HTTPServer(app)
    http_server.listen(options.options.port)
    ioloop.IOLoop.current().start()


if __name__ == '__main__':
    main()
